import { IInputDevice } from '../../interface/IInputDevice';

/**
 * 组合键
 */
export class KeyCombo {

    keyList: number[] = [];
    constructor(...keys: number[]) {
        this.keyList = keys;
    }

    // 判断组合键是否成功触发
    public isTrigger(keyInput: IInputDevice): boolean {
        //最后一个键必须是刚按下
        const lastKey = this.keyList[this.keyList.length - 1];
        if (!keyInput.getKeyDown(lastKey)) return false;
        //其他键必须是按下状态
        for (let i = 0; i < this.keyList.length - 1; i++) {
            const key = this.keyList[i];
            if (!keyInput.getKey(key)) return false;
        }
        return true;
    }
}
